{x2;if:!$userhash}
{x2;include:header}
<body>
{x2;include:nav}
<div class="container-fluid">
    <div class="row-fluid">
        <div class="main">
            <div class="col-xs-2" style="padding-top:10px;margin-bottom:0px;">
                {x2;include:menu}
            </div>
            <div class="col-xs-10" id="datacontent">
                {x2;endif}
                <div class="box itembox" style="margin-bottom:0px;border-bottom:1px solid #CCCCCC;">
                    <div class="col-xs-12">
                        <ol class="breadcrumb">
                            <li><a href="index.php?{x2;$_app}-master">{x2;$apps[$_app]['appname']}</a></li>
                            <li><a href="index.php?{x2;$_app}-master-questions">试题管理</a></li>
                            <li class="active">试题分布统计</li>
                        </ol>
                    </div>
                </div>
                <div class="box itembox" style="padding-top:10px;margin-bottom:0px;">
                    <h4 class="title" style="padding:10px;">
                        试题分布统计
                    </h4>
                    <blockquote>
                        <p>PS：<b class="text-success">绿色块 - 易 (基础知识点)</b> | <b class="text-warning">黄色块 - 中
                                (重点/测试分差)</b> | <b class="text-danger">红色块 - 难 (面试/优选/实例)</b></p>
                    </blockquote>
                    <table class="table table-hover table-bordered" id="sum">
                        <tr class="info">
                            <th class="text-center">
                                <button class="btn btn-danger btn-sm ck" data-on="off">选/取</button>
                            </th>
                            <th class="text-center">知识点</th>
                            <th class="text-center">题目数</th>
                            <th class="text-center" colspan="3">单选</th>
                            <th class="text-center" colspan="3">多选</th>
                            <th class="text-center" colspan="3">填空</th>
                            <th class="text-center" colspan="3">问答</th>
                        </tr>
                        {x2;tree:$dists,val,k}
                        <tr class="text-center">
                            <td><input type="checkbox" data-id="{x2;v:key}" id="num{x2;v:key}"></td>
                            <td class="text-left"><label for="num{x2;v:key}">{x2;v:val['knows']}</label></td>
                            <td class="text-right">{x2;v:val['knowtotal']} 题</td>

                            <td class="success num">
                                {x2;if:v:val['questiontype'][1]['easy'] !== null}
                                {x2;v:val['questiontype'][1]['easy']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="warning num">
                                {x2;if:v:val['questiontype'][1]['nomal'] !== null}
                                {x2;v:val['questiontype'][1]['nomal']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="danger num">
                                {x2;if:v:val['questiontype'][1]['difficult'] !== null}
                                {x2;v:val['questiontype'][1]['difficult']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>

                            <td class="success num">
                                {x2;if:v:val['questiontype'][2]['easy'] !== null}
                                {x2;v:val['questiontype'][2]['easy']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="warning num">
                                {x2;if:v:val['questiontype'][2]['nomal'] !== null}
                                {x2;v:val['questiontype'][2]['nomal']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="danger num">
                                {x2;if:v:val['questiontype'][2]['difficult'] !== null}
                                {x2;v:val['questiontype'][2]['difficult']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>

                            <td class="success num">
                                {x2;if:v:val['questiontype'][5]['easy'] !== null}
                                {x2;v:val['questiontype'][5]['easy']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="warning num">
                                {x2;if:v:val['questiontype'][5]['nomal'] !== null}
                                {x2;v:val['questiontype'][5]['nomal']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="danger num">
                                {x2;if:v:val['questiontype'][5]['difficult'] !== null}
                                {x2;v:val['questiontype'][5]['difficult']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>

                            <td class="success num">
                                {x2;if:v:val['questiontype'][6]['easy'] !== null}
                                {x2;v:val['questiontype'][6]['easy']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="warning num">
                                {x2;if:v:val['questiontype'][6]['nomal'] !== null}
                                {x2;v:val['questiontype'][6]['nomal']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                            <td class="danger num">
                                {x2;if:v:val['questiontype'][6]['difficult'] !== null}
                                {x2;v:val['questiontype'][6]['difficult']}
                                {x2;else}
                                0
                                {x2;endif}
                            </td>
                        </tr>
                        {x2;endtree}
                    </table>

                    <hr>
                    <button class="btn-block btn-lg btn-danger btn-sum">统计选中的题目数</button>
                    <table id="result" class="table table-bordered h4">
                        <tr>
                            <th class="text-center col-md-2">已选题目总数</th>
                            <th class="text-center" colspan="3">单选</th>
                            <th class="text-center" colspan="3">多选</th>
                            <th class="text-center" colspan="3">填空</th>
                            <th class="text-center" colspan="3">简答</th>
                        </tr>
                        <tr class="text-center">
                            <td rowspan="2"><h1 class="text-danger" id="total">00</h1></td>
                            <td class="success">0</td>
                            <td class="warning">0</td>
                            <td class="danger">0</td>
                            <td class="success">0</td>
                            <td class="warning">0</td>
                            <td class="danger">0</td>
                            <td class="success">0</td>
                            <td class="warning">0</td>
                            <td class="danger">0</td>
                            <td class="success">0</td>
                            <td class="warning">0</td>
                            <td class="danger">0</td>
                        </tr>
                        <tr class="text-center">
                            <td colspan="3" class="sub">0</td>
                            <td colspan="3" class="sub">0</td>
                            <td colspan="3" class="sub">0</td>
                            <td colspan="3" class="sub">0</td>
                        </tr>
                    </table>
                </div>
            </div>
            {x2;if:!$userhash}
        </div>
    </div>
</div>

{x2;include:footer}

<script>
    $(function () {
        // 全选/全取
        $('.ck').click(function () {
            var cks = $('#sum :checkbox');
            if ($(this).attr('data-on') === 'off') {
                $(this).attr('data-on', 'on');
                for (let i = 0; i < cks.length; i++) {
                    cks[i].checked=true;
                }
            } else {
                $(this).attr('data-on', 'off');
                for (let i = 0; i < cks.length; i++) {
                    cks[i].checked=false;
                }
            }
        });

        $('.btn-sum').click(function () {
            // 找到所有带复选框的
            var list = $('#sum :checkbox:checked');
            // 如果未选统计内容,则提示去框选
            if (list.length === 0) {
                alert('请先勾选【要统计的知识点】再统计!');
                return;
            }

            // 将DOM中的各个数字,有序的存储到数组中
            var data = [];
            for (let i = 0; i < list.length; i++) {
                data[i] = [];
                var dataDOM = $(list[i]).parents('tr').children('td.num');
                for (let j = 0; j < dataDOM.length; j++) {
                    data[i].push(parseInt(dataDOM[j].innerText));
                }
            }

            // 计算题目数
            var res = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
            // 以有题目数的数组为 总计算循环
            for (let i = 0; i < data.length; i++) {
                // 以12个总统计数列为 求和次数,求和12种题的值
                for (let j = 0; j < res.length; j++) {
                    // 在计算总题数的数组里,累加已选知识点的各类题目数量
                    res[j] += data[i][j];
                }
            }

            // 写入结果到指定处
            var resDOM = $('#result tr:eq(1) td:gt(0)');
            var total = 0;
            var a = 0;
            var subtotal = [];
            for (let i = 0; i < resDOM.length; i++) {
                resDOM[i].innerHTML = res[i];
                total += res[i];
                a += res[i];
                if ((i+1) % 3 === 0) {
                    subtotal.push(a);
                    a = 0;
                }
            }
            // 计算总题数和子题数,并写入
            $('#total').html(total);
            for (let i = 0; i < subtotal.length; i++) {
                $('#result .sub')[i].innerText = subtotal[i];
            }
        });

        setTimeout(function() {
            $('.ck').click();
            $('.btn-sum').click();
        }, 1000);

    });
</script>
<script type="text/javascript" src="https://s9.cnzz.com/z_stat.php?id=1277952714&web_id=1277952714"
        async="async"></script>
</body>
</html>
{x2;endif}
